// subPages/pensionService/serviceDoor/serviceDoor.js
const app = getApp();
var util = require('../../../utils/util');
var num=4,p=1,loadMoreView,type
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeColor:app.globalData.themeColor
  },
  makecall(e){
      let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
        phoneNumber:phone
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      loadMoreView = this.selectComponent("#loadMoreView")
      util.setNavBarTitle('服务上门');
      util.setNavBarColor('#ffffff',this.data.themeColor);
      this.getHomemakingService();
  },
    getHomemakingService(){
        var that = this;
        let type = that.data.type,url;
        util.getAjax(`${app.globalData.apiUrl}/get_community_service_up_home_work`,function(res){
            console.log(res);
            if(res.data.list.length != 0){
                var list = [];
                if(p == 1){
                    list = res.data.list
                }else{
                    list = that.data.homemakingServiceList.concat(res.data.list)
                }
                that.setData({
                    homemakingServiceList:list
                })
            }else{
                that.setData({
                    homemakingServiceList:[]
                })
            }
            loadMoreView.loadMoreComplete(res.data,type)
        },{
            p:p,
            num:num,
            community_id:app.globalData.communityId
        })
    },
    //获取服务数据异常
    shopDataErr(err){
        if(p>1){
            loadMoreView.loadMoreFail()
        }else{
            util.showModal('提示','获取商品失败，请向上滑动屏幕')
            this.setData({
                isFail: true
            })
        }
    },
    loadMoreListener: function(e) {
        p += 1
        this.getHomemakingService()
    },

    clickLoadMore: function(e) {
        this.getHomemakingService()
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      if(this.data.isFail){
          this.getHomemakingService()
          return
      }
      loadMoreView.loadMore()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
